<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head th:include="base/head.html::static">
<title>审核界面</title>
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">

    <!--左侧导航-->
    <aside class="lyear-layout-sidebar" th:include="base/base.html::left"></aside>

    <!--头部信息-->
    <header class="lyear-layout-header" th:include="base/base.html::header"></header>
    
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-toolbar clearfix">
                <div class="toolbar-btn-action">
                  <a class="btn btn-success m-r-5" href="#!" onclick="approLeaveNote(this)" id="success"><i class="mdi mdi-check"></i> 通过</a>
                  <a class="btn btn-danger" href="#!" onclick="approLeaveNote(this)"><i class="mdi mdi-window-close"></i> 不通过</a>
                </div>
              </div>
              <div class="card-body">
                
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>
                          <label class="lyear-checkbox checkbox-primary">
                            <input type="checkbox" id="check-all"><span></span>
                          </label>
                        </th>
                        <th>编号</th>
                        <th>系部</th>
                        <th>班级</th>
                        <th>姓名</th>
                        <th>申请时间</th>
                        <th>申请状态</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody id="leaveNoteList">
                      <tr th:each="leaveNote:${result.records}">
                        <td th:if="${leaveNote.state == 0}">
                          <label class="lyear-checkbox checkbox-primary">
                            <input type="checkbox" name="ids[]" th:value="${leaveNote.id}"><span></span>
                          </label>
                        </td>
                        <td th:if="${leaveNote.state != 0}"></td>
                        <td th:text="${leaveNote.id}">1</td>
                        <td th:text="${leaveNote.departmentName}">信息工程学院</td>
                        <td th:text="${leaveNote.className}">软件1722</td>
                        <td th:text="${leaveNote.userName}">pxl</td>
                        <td th:text="${#dates.format(leaveNote.timeStudent,'yyyy-MM-dd HH:mm:ss')}">2019-2-2 12:23</td>
                        <td th:if="${leaveNote.state == 1}"><font class="text-success">审核通过</font></td>
                        <td th:if="${leaveNote.state == 0}"><font class="text-warning">未审核</font></td>
                        <td th:if="${leaveNote.state == -1}"><font class="text-danger">审核未通过</font></td>
                        <td>
                          <div class="btn-group">
                            <a class="btn btn-xs btn-default" th:href="${'/leave-note/Onelog/'+leaveNote.id}" title="查看" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
                          </div>
                        </td>
                    </tbody>
                  </table>
                </div>
                <ul class="pagination">
                  <li th:class="${result.current == 1 } ? disabled: ''"><a th:href="@{/leave-note/log/1}">«</a></li>
                  <li th:if="${result.current-6 > 0 and result.current+1 > maxPage}"><a th:href="${'/leave-note/appro/'+ (result.current-6)}" th:text="${result.current-6}">当前页的前6页</a></li>
                  <li th:if="${result.current-5 > 0 and result.current+2 > maxPage}"><a th:href="${'/leave-note/appro/'+ (result.current-5)}" th:text="${result.current-5}">当前页的前5页</a></li>
                  <li th:if="${result.current-4 > 0 and result.current+3 > maxPage}"><a th:href="${'/leave-note/appro/'+ (result.current-4)}" th:text="${result.current-4}">当前页的前4页</a></li>
                  <li th:if="${result.current-3 > 0}"><a th:href="${'/leave-note/appro/'+ (result.current-3)}" th:text="${result.current-3}">当前页的前3页</a></li>
                  <li th:if="${result.current-2 > 0}"><a th:href="${'/leave-note/appro/'+ (result.current-2)}" th:text="${result.current-2}">当前页的前2页</a></li>
                  <li th:if="${result.current-1 > 0}"><a th:href="${'/leave-note/appro/'+ (result.current-1)}" th:text="${result.current-1}">当前页的前1页</a></li>
                  <li class="active" ><a th:text="${result.current}" href="#">1</a></li>
                  <li th:if="${result.current+1 <= maxPage}"><a th:href="${'/leave-note/appro/'+ (result.current+1)}" th:text="${result.current+1}">当前页的后1页</a></li>
                  <li th:if="${result.current+2 <= maxPage}"><a th:href="${'/leave-note/appro/'+ (result.current+2)}" th:text="${result.current+2}">当前页的后2页</a></li>
                  <li th:if="${result.current+3 <= maxPage}"><a th:href="${'/leave-note/appro/'+ (result.current+3)}" th:text="${result.current+3}">当前页的后3页</a></li>
                  <li th:if="${result.current+4 <= maxPage and result.current-3 <= 0}"><a th:href="${'/leave-note/appro/'+ (result.current+4)}" th:text="${result.current+4}">当前页的后4页</a></li>
                  <li th:if="${result.current+5 <= maxPage and result.current-2 <= 0}"><a th:href="${'/leave-note/appro/'+ (result.current+5)}" th:text="${result.current+5}">当前页的后5页</a></li>
                  <li th:if="${result.current+6 <= maxPage and result.current-1 <= 0}"><a th:href="${'/leave-note/appro/'+ (result.current+6)}" th:text="${result.current+6}">当前页的后6页</a></li>
                  <li th:class="${result.current == maxPage } ? disabled: ''"><a th:href="${'/leave-note/appro/'+ maxPage}">»</a></li>
                </ul>
       
              </div>
            </div>
          </div>
          
        </div>
        
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </div>
</div>
<script type="text/javascript" th:inline="javascript">
  var approLeaveNote=function (element) {
    var  text=element.text;
    var success=$('#success').text();
    var state=text==success?1:-1;
    //获取名字
    var teacherName=[[${session.user.realName}]];
    //获取选中的复选框
    var ids=[];
    $('input[name="ids[]"]:checked').each(function(){//遍历每一个名字为ids[]的复选框，其中选中的执行函数
      ids.push($(this).val());//将选中的值添加到数组ids中
    });
    alert(JSON.stringify(ids));
    axios({
      method:'put',
      url:"/leave-note/appro",
      data:{
        state: state,
        ids:ids,
        teacherName:teacherName
      }
    }).then(
            function (response) {
              //为什么会发两次请求
              alert(response.data);
              if(response.data=='审核成功'){
                window.location.replace("/leave-note/appro/1");
              }
            }
    );

  }

</script>
</body>
</html>